package com.ruoyi.cake.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cake.domain.Cake;
import com.ruoyi.cake.service.ICakeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 蛋糕Controller
 *
 * @author zichen
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/cake/cake")
public class CakeController extends BaseController
{
    @Autowired
    private ICakeService cakeService;

    /**
     * 查询蛋糕列表
     */
    @PreAuthorize("@ss.hasPermi('cake:cake:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cake cake)
    {
        startPage();
        List<Cake> list = cakeService.selectCakeList(cake);
        return getDataTable(list);
    }

    /**
     * 导出蛋糕列表
     */
    @PreAuthorize("@ss.hasPermi('cake:cake:export')")
    @Log(title = "蛋糕", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cake cake)
    {
        List<Cake> list = cakeService.selectCakeList(cake);
        ExcelUtil<Cake> util = new ExcelUtil<Cake>(Cake.class);
        util.exportExcel(response, list, "蛋糕数据");
    }

    /**
     * 获取蛋糕详细信息
     */
    @PreAuthorize("@ss.hasPermi('cake:cake:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cakeService.selectCakeById(id));
    }

    /**
     * 新增蛋糕
     */
    @PreAuthorize("@ss.hasPermi('cake:cake:add')")
    @Log(title = "蛋糕", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cake cake)
    {
        return toAjax(cakeService.insertCake(cake));
    }

    /**
     * 修改蛋糕
     */
    @PreAuthorize("@ss.hasPermi('cake:cake:edit')")
    @Log(title = "蛋糕", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cake cake)
    {
        return toAjax(cakeService.updateCake(cake));
    }

    /**
     * 出库
     */
    @PostMapping("/outbound")
    public AjaxResult outbound(@RequestBody Cake cake)
    {
        return toAjax(cakeService.outbound(cake));
    }

    /**
     * 删除蛋糕
     */
    @PreAuthorize("@ss.hasPermi('cake:cake:remove')")
    @Log(title = "蛋糕", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cakeService.deleteCakeByIds(ids));
    }
}
